package top.hkyzf.study.leetcode.linkedlist;

import org.junit.Test;

/**
 * @author 朱峰
 * @date 2022-2-17 10:43
 */
public class 删除排序链表中的重复元素_83 {
    public ListNode deleteDuplicates(ListNode head) {
        ListNode cur = head;
        while (cur != null && cur.next != null) {
            if (cur.val == cur.next.val) {
                cur.next = cur.next.next;
            } else {
                cur = cur.next;
            }
        }
        return head;
    }

    @Test
    public void testDeleteDuplicates () {
        ListNode node4 = new ListNode(3);
        ListNode node3 = new ListNode(3, node4);
        ListNode node2 = new ListNode(2, node3);
        ListNode node1 = new ListNode(1, node2);
        ListNode head1 = new ListNode(1, node1);
        ListNode head = deleteDuplicates(head1);
        while (head != null) {
            System.out.println(head);
            head = head.next;
        }
    }
}
